package lily.ui.control;

import lily.phs.urh.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyArrayAdapter extends BaseAdapter{
	
	Context context;
	String[] ItemNames;
	int count;
	
	public MyArrayAdapter(Context arg2, String[] ItemNames){
		this.context = arg2;
		this.ItemNames = ItemNames;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return ItemNames.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
			
		LayoutInflater factory = LayoutInflater.from(context);	
		View localView = factory.inflate(R.layout.ayyaylist_item_view, null);
		
		ViewHolder mViewHolder = new ViewHolder();
		mViewHolder.tv = (TextView)localView.findViewById(R.id.itemname);
		
		count = getCount();
		
		if (position == 0){//第一项
			String str1 = ItemNames[0];
			mViewHolder.tv.setText(str1);
			
			localView.setBackgroundResource(R.drawable.circle_list_top);
		}

		if (position> 0&position<count-1){
			String str1 = ItemNames[position];
			mViewHolder.tv.setText(str1);
			
			localView.setBackgroundResource(R.drawable.circle_list_middle);
		}
		
		if(position == count-1){
			String str1 = ItemNames[count-1];
			mViewHolder.tv.setText(str1);
			
			localView.setBackgroundResource(R.drawable.circle_list_bottom);	
		}

		return localView;
	
	}
	
	
	/*listitem的自定义视图*/
	class ViewHolder
	{
		TextView tv;

		ViewHolder()
		{
		}
	}

}
